/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pig4cloud.pigx.strategy.mapper;

import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.strategy.entity.StrategyTaskContract;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 策略任务-合约
 *
 * @since 2022-11-24 10:39:27
 */
@Mapper
public interface StrategyTaskContractMapper extends PigxBaseMapper<StrategyTaskContract> {

    /**
     * 新增
     *
     * @param entity 数据
     * @return {@link int}
     * @since 2022/11/28 14:37
     */
    int add(StrategyTaskContract entity);

    /**
     * 同步订单信息成功时查询任务信息，锁定
     *
     * @param taskId 任务id
     * @return {@link StrategyTaskContract}
     * @since 2022/12/2 14:17
     */
    StrategyTaskContract selectWhenSyncOrder(Long taskId);

    /**
     * 查询用户利润
     *
     * @param userId    用户id
     * @param startTime 起始时间
     * @param endTime   截止时间
     * @return {@link BigDecimal}
     * @since 2022/12/10 16:05
     */
    BigDecimal profit(@Param("userId") Long userId,
                      @Param("startTime") Date startTime,
                      @Param("endTime") Date endTime);

    /**
     * 根据策略id和状态查询id集合
     * <p>从旧到新
     *
     * @param strategyId 策略id
     * @param statusList 状态集合
     * @param startIndex 起始下标
     * @param endIndex   结束下标
     * @return {@link List < Long>}
     * @since 2022/12/10 11:46
     */
    List<Long> getIdListByStrategyIdAndStatusList(@Param("strategyId") Long strategyId,
                                                  @Param("statusList") List<String> statusList,
                                                  @Param("startIndex") int startIndex,
                                                  @Param("endIndex") int endIndex);
}
